<!DOCTYPE html>
<html lang="en">
<head>
    <meta charset="UTF-8">
    <meta name="viewport" content="width=device-width, initial-scale=1.0, maximum-scale=1.0, user-scalable=0">
    <meta name="apple-mobile-web-app-capable" content="yes">
    <meta name="apple-mobile-web-app-status-bar-style" content="black">
    <meta name="format-detection" content="telephone=no">
    <meta name="description" content="">
    <meta http-equiv="x-dns-prefetch-control" content="on">
    <style>
        .set_top {
            position: absolute;
            left: 30%;
            opacity: 0;
            top: 30%;
        }
    </style>
    <title>完成订单</title>
    <link href="../../css/css.css" rel="stylesheet" type="text/css">
    <script src="../../js/jquery-v1.11.2.min.js"></script>
    <script src="../../js/driver.js"></script>
    <script src="../../js/common.js"></script>
    <script src="../../js/ajaxfileupload.js"></script>
</head>
<body>
<section class="itemgroup mt5 p15">
    <div class="twoitem_xl" >
        <!--<i class="iconfont mr5 red icon28">&#xe70c;</i>-->

        <span id="endAddr">
            <i class="iconfont mr5 red icon28">&#xe70c;</i>

        </span>
        <span class="mt10" id="endCross">
            <i class="iconfont mr5 gray icon28">&#xe723;</i>

        </span>
    </div>
    <div class="oneitem_xl">
        <label class="gray mr5">收货人:</label>
        <span id="consignName"></span>
        <i class="iconfont rightsmallicon">&#xe6db;</i>
        <label class="right" id="consignMobile" onclick="call();"></label>
    </div>
</section><!--
<section class="p15 subtitle_xl mt10">实际行驶距离</section>
<section class="itemgroup">
    <div class="wait_time">
        <span id="realDistince">0</span><span class="icon25">公里</span>
        <span id="realFee">0</span><span class="icon25">元</span>
    </div>
</section>-->
<section class="p15 subtitle_xl mt3">实际行驶距离</section>
<section class="itemgroup">
    <div class="wait_time">
        <span id="realDistince">0</span><span class="icon25">公里</span>
    </div>
</section>
<section class="p15 subtitle_xl mt3">实时费用</section>
<section class="itemgroup">
    <div class="wait_time">
        <span id="realFee">0</span><span class="icon25">元</span>
    </div>
</section>
<section class="sale_info_xl">实际费用可能因实际行驶里程/等候时间等因素差异</section>
<section class="p15 subtitle_xl mt3" style="display:none;">添加卸货后照片</section>
<section class="itemgroup p15" style="display:none;">
    <div class="add_photo_xl" style="position: relative;" id="add_photo_xl">
        <i class="iconfont">&#xe60d;</i>
    </div>
    <div class="add_photo_info">
        为了保障司机权益及货物安全，避免客户投诉，请点击左侧按钮拍摄货物装车后的照片
        <p>查看示例</p>
    </div>
</section>
<section class="bottomarea">
    <button type="button" class="btn bottomonebtn_xl" id="goonBid5" onclick="goonBid5()">完成订单</button>
</section>
<form id="dataForm">
    <input type="hidden" name="waybillId" id="waybillId">
    <input type="hidden" id="longitude" name="lon">
    <input type="hidden" id="latitude" name="lat">
    <input type="hidden" name="driverUserId" id="driverUserId">
    <input type="hidden" name="pictureId" id="pictureId">
    <input type="hidden" name="billAttachId" id="billAttachId">
    <input type="hidden" name="realPath" id="realPath">
</form>
<script type="text/javascript">
    $(function () {
        //token验证
        checkDriverToken();
    });
    var waybillId=0;
    $(document).ready(function () {
    		checkService();
        waybillId = GetArgsFromHref("waybillId");
        
        try{
		    	delegate.setCookie("billidcookie", waybillId+"");
				}catch(e){}
		    	
        var url = _global.serverHost + "/driver/goon_bid4.htm";
        var data = {waybillId: waybillId,driverUuid: getCookie("driverUuid")};
        _callAjaxRequest(url, data, startBidBack);

        $("#waybillId").val(waybillId);

        function startBidBack(data) {
            $("#endAddr").html('<i class="iconfont mr5 red icon28">&#xe70c;</i>&nbsp;' + data.waybill.endStreet);
            $("#endCross").html('<i class="iconfont mr5 gray icon28">&#xe723;</i>&nbsp;' + data.waybill.endCross);
            $("#consignName").html(data.waybill.consignName);
            $("#consignMobile").html(data.waybill.consignMobile);
            tel = data.waybill.consignMobile;
            //$("#costTime").html(data.costTime);
            //$("#realFee").html(data.waybill.planStartFee);
            ////////////////////
            $("#driverUserId").val(data.driverUserId);
            $("#pictureId").val(data.waybill.pictureId);
            $("#billAttachId").val(data.billAttach != null ? data.billAttach.billAttachId : "");
            console.log("========="+$("#billAttachId").val());
            $("#realPath").val(data.realPath);
            arriveDate = data.waybill.arriveDate;

            var add_photo_xl = "";
            add_photo_xl = '<div class="delphoto" style="top:-45px"';
            if (data.billAttach == null || data.billAttach.savePath == null) add_photo_xl = add_photo_xl + "hidden";
            add_photo_xl = add_photo_xl + ' id="unloadImageDelDiv" onclick="deleteImage(\'unloadImage\')"> ' +
                    '<img src="../../img/del_btn.png" width="100%" height="100%"/>' +
                    '</div>' +
                    '<div id="unloadImageOtherReal" ';
            if (data.billAttach != null && data.billAttach.savePath != null) add_photo_xl = add_photo_xl + "hidden";
            add_photo_xl = add_photo_xl + ' ><input type="file" onchange="loadHead(\'unloadImage\');" id="unloadImage"' +
                    'name="unloadImage" class="set_top"/>' +
                    '<i class="iconfont">&#xe60d;</i>' +
                    '</div>';
            var imgUrl = "";
            if (data.billAttach == null || data.billAttach.savePath == null)
                imgUrl = "#";
            else
                imgUrl = data.realPath + data.billAttach.savePath;
            add_photo_xl = add_photo_xl + '<img src="' + imgUrl + '" width="100%" height="100%" ';
            if (data.billAttach == null || data.billAttach.savePath == null) add_photo_xl = add_photo_xl + "hidden";
            add_photo_xl = add_photo_xl + '  id="unloadImageReal"/>';
            $("#add_photo_xl").html(add_photo_xl);
        }
    });
    /*取消到达卸货点节点
    function goonBid5() {
    	var update = confirm('您确定到达卸货点了吗？');
        if (update) {
            var url = _global.serverHost + "/driver/check_goon_bid4.htm";
		        var data = {waybillId: waybillId,driverUuid: getCookie("driverUuid")};
		        _callAjaxRequest(url, data, goonBid5Back);
        }
    }
    function goonBid5Back(data) {
        if (data.code == "1") {
            window.location.href = "../start_bid/goon_bid5.html?waybillId=" + data.waybillId;
        } else {
            alert(data.message);
        }
    }
    */
    function goonBid5() {
    	var update = confirm('您确定结束卸货并最终完成订单了吗？');
        if (update) {
        	$.ajax({
                type: "POST",
                url: _global.serverHost + "/driver/check_goon_bid4.htm",
                data: {waybillId: waybillId,driverUuid: getCookie("driverUuid"),isUnload:'1'},
                contentType: "application/x-www-form-urlencoded;charset=UTF-8",
                success: function (data) {
                	if (data.code == "1") {
		                		try{
										       delegate.removeCookie("billidcookie");
										    }catch(e){}	
                        //window.location.href = "../start_bid/goon_bid5.html?waybillId=" + data.waybillId;
                				window.location.href = "../start_bid/ok_bid.html?waybillId=" + data.waybillId;
                    } else {
                        alert(data.message);
                    }
                }
            });
        	
        }
    }
    
    window.setTimeout("getRealDistince()", 100);
    window.setInterval("getRealDistince()", 4000);
    function getRealDistince() {
        $.ajax({
            type: "POST",
            url: _global.serverHost + "/driver/get_real_distince.htm",
            data: {waybillId: $("#waybillId").val(),driverUuid: getCookie("driverUuid")},
            contentType: "application/x-www-form-urlencoded;charset=UTF-8",
            success: function (data) {
                if (data != null) {
                    $("#realDistince").html(data.distance);
                    $("#realFee").html(data.fee);
                }
            }
        });
    }
    
    function checkService(){
				try{
        	delegate.checkServiceManual();
      	}catch(e){}
　     setTimeout("checkService()", 10000);
   	} 
    
    var tel = "";
    function call() {
        delegate.call(tel);
    }
    
    function deleteImage(fileElementId) {
        $.ajax({
            type: "POST",
            url: _global.serverHost + "/driver/deleteImage.htm",
            data: {billAttachId: $("#billAttachId").val(),driverUuid: getCookie("driverUuid")},
            contentType: "application/x-www-form-urlencoded;charset=UTF-8",
            success: function (data) {
                if (data.code == "1") {
                    $("#" + fileElementId + "Real").attr("src", "#");
                    $("#" + fileElementId + "OtherReal").show();
                    $("#" + fileElementId + "Real").hide();
                    $("#" + fileElementId + "DelDiv").hide();
                    $("#pictureId").val("");
                    $("#billAttachId").val("");
                } else {
                    alert(data.message);
                }
            }
        });
    }

    function loadHead(fileElementId) {
    	var fileGuid=guid();
    	var frameId=new Date().getTime();//"jUploadFrame"+frameId
        $.ajaxFileUpload({
            url: _global.serverHost + "/driver/uploadVehicle.htm?driverUserId=" + $("#driverUserId").val() + "&billId=" + $("#waybillId").val() + "&pictureId=" + $("#pictureId").val() + "&fileElementId=" + fileElementId+ "&driverUuid=" + getCookie("driverUuid")+"&guid="+fileGuid,
            secureuri: false,
            fileElementId: fileElementId,//文件选择框的id属性
            dataType: 'json',   //json
            id:frameId,
            success: function (ajaxfileuploaddata) {
            	$.ajax({
                    type: "POST",
                    url: _global.serverHost + "/driver/getImageByGuid.htm",
                    data: {guid: fileGuid,driverUuid: getCookie("driverUuid")},
                    contentType: "application/x-www-form-urlencoded;charset=UTF-8",
                    success: function (data) {
                    	$("#" + fileElementId + "Real").attr("src", data.fileUrl);
                        $("#" + fileElementId + "OtherReal").hide();
                        $("#" + fileElementId + "Real").show();
                        $("#" + fileElementId + "DelDiv").show();
                        $("#pictureId").val(data.pictureId);
                        $("#billAttachId").val(data.billAttachId);
                    }
                });
            }, 
            error: function (XMLHttpRequest, textStatus, errorThrown) {
            	console.log("====ajax上传文件失败！");
                alert('上传失败！');
            }
        });
    }
/*    function uploadLocation() {
        var loc = "31.12345,121.23456";
        if (typeof javaHandler != "undefined") {
            loc = javaHandler.getCurrentLocation();
        }
        var locs = loc.split(",");
        $("#longitude").val(locs[1]);
        $("#latitude").val(locs[0]);
        var json_data = {
            waybillId: waybillId,
            lat: locs[0],
            lon: locs[1],
            driverUuid: getCookie("driverUuid"),
            comment: "定时定位"
        };

        if (_global.sendPost == "0") {
            _callAjaxRequest(_global.serverHost + '/driver/location.htm', json_data, function (data) {
                console.log(JSON.stringify(data));
            });
        } else {
            callHTTPRequestLogon(JSON.stringify(json_data));//app调用
        }
        var timer = setTimeout("uploadLocation()", 60000);//60秒
    }*/
</script>
</body>
</html>